package com.peng.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peng.result.Result;
import com.peng.service.UserInfoService;
import com.peng.yygh.model.user.UserInfo;
import com.peng.yygh.vo.acl.UserQueryVo;
import com.peng.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Integer page, @PathVariable Integer limit , UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page1 = new Page<>(page, limit);
        Page<UserInfo> userInfoPage= userInfoService.selectPage(page1,userInfoQueryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Integer userId,@PathVariable Integer status){
        UserInfo userInfo = userInfoService.getById(userId);
        userInfo.setStatus(status);
        userInfoService.updateById(userInfo);
        return Result.ok();
    }

    //用户详情
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    //认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        UserInfo byId = userInfoService.getById(userId);
        byId.setAuthStatus(authStatus);
        userInfoService.updateById(byId);
        return Result.ok();
    }
}
